package com.qiaotongtianxia.loans.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.qiaotongtianxia.loans.R;
import com.qiaotongtianxia.loans.functionInterface.IBaseRequestImp;
import com.qiaotongtianxia.loans.net.Api;
import com.qiaotongtianxia.loans.util.ToastUtil;
import com.qiaotongtianxia.loans.views.BaseTextView;

import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by lisen on 2017/12/19.
 *
 * @author lisen < 4533548588@qq.com >
 */

public class ServiceActivity extends BaseActivity {
    @BindView(R.id.tv_nav_title)
    BaseTextView tvNavTitle;
    @BindView(R.id.tv_phone)
    BaseTextView tvPhone;
    @BindView(R.id.tv_qq)
    BaseTextView tvQq;

    @Override
    public int getLayoutId() {
        return R.layout.activity_service;
    }

    @Override
    public void onBaseCreate(@Nullable Bundle savedInstanceState) {

        api.service(new IBaseRequestImp<Map<String, String>>() {
            @Override
            public void onRequestSuccess(Map<String, String> result) {
                tvPhone.setText(result.get("phone"));
                tvQq.setText(result.get("qq"));
            }
        });
    }

    @Override
    public Api onApiCreate() {
        return new Api(this);
    }

    @OnClick({R.id.iv_nav_back, R.id.tv_phone, R.id.tv_qq})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_nav_back:
                finish();
                break;
            case R.id.tv_phone:

                Intent phone = new Intent(Intent.ACTION_DIAL);
                phone.setData(Uri.parse("tel:"+tvPhone.getText().toString()));
                startActivity(phone);
                break;
            case R.id.tv_qq:
                try{
                    String url="mqqwpa://im/chat?chat_type=wpa&uin=";
                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url+tvQq.getText().toString())));
                }catch (Exception e){
                    e.printStackTrace();
                    ToastUtil.showShort(ServiceActivity.this,"无法启动QQ");
                }
                break;
        }
    }

    @Override
    public void initTitle() {
        tvNavTitle.setText(getString(R.string.service));
    }
}
